package com.vip.oauth2resource.util;

import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.io.Serializable;
import java.util.Collection;
import java.util.List;

/**
 * 自定义userDetail 关联security oauth2
 *
 * @author wgb
 * @date 2020/3/4
 */
@Setter
@Getter
@Accessors(chain = true)
public class CustomUserDetail implements UserDetails, Serializable {
    private static final long serialVersionUID = -8478114427891717226L;

    /**
     * 用户id
     */
    private String id;
    /**
     * 用户名
     */
    private String username;
    /**
     * 用户昵称
     */
    private String name;
    /**
     * 密码
     */
    private String password;
    /**
     * 登录名
     */
    private String account;
    /**
     * 描述
     */
    private String description;
    /**
     * 已通过的Token
     */
    private String accessToken;
    /**
     * 账户生效
     */
    private boolean accountNonExpired = true;
    /**
     * 账户锁定
     */
    private boolean accountNonLocked = true;
    /**
     * 凭证生效
     */
    private boolean credentialsNonExpired = true;
    /**
     * 激活状态
     */
    private boolean enabled = true;
    /**
     * 权限列表
     */
    private Collection<GrantedAuthority> authorities;
    /**
     * accessToken是否过期
     */
    private Boolean expired;
    /**
     * accessToken到期时间
     */
    private String accessTokenExpiration;
    /**
     * accessToken过期时限
     */
    private Integer accessTokenExpiresIn;
    /**
     * 使用范围
     */
    private List<String> scope;
    /**
     * token类型
     */
    private String tokenType;

    /**
     * refreshToken到期时间
     */
    private String refreshTokenExpiration;
    /**
     * refreshToken码
     */
    private String refreshToken;

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return authorities;
    }

    @Override
    public String getPassword() {
        return password;
    }

    @Override
    public String getUsername() {
        return username;
    }

    @Override
    public boolean isAccountNonExpired() {
        return accountNonExpired;
    }

    @Override
    public boolean isAccountNonLocked() {
        return accountNonLocked;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return credentialsNonExpired;
    }

    @Override
    public boolean isEnabled() {
        return enabled;
    }

}
